package com.ghost.UI
{
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import com.ghost.event.Skin_Event;
	
	import fl.controls.ColorPicker;
	
	import flash.events.Event;

	/**
	 * @author ghost
	 * 颜色拾色器
	 */
	public class Ghost_colorpicker extends ColorPicker
	{
		/**
		 * @param skin_v 皮肤数据 顺序:
		 * 弹出背景，填充了一种颜色时颜色池外观的类，绘制 ColorPicker 组件中包含的样本的外观的类,用于加亮显示当前所选颜色的外观的类,
		 * ColorPicker 组件的文本字段背景的类,ColorPicker 中被禁用按钮的外观的类,ColorPicker按钮处于按下位置时的外观的类,
		 * 悬停于颜色池上方时颜色池的外观的类,ColorPicker 按钮处于弹起位置时的外观的类
		 */		
		private var style_v:Vector.<Class>;//皮肤数据
		private var style_str_v:Vector.<String>;//样式名
		private var style_length:int = 9;//设置样式的个数
		public function Ghost_colorpicker(skin_v:Vector.<Class>=null)
		{
			this.addEventListener(Event.REMOVED_FROM_STAGE,remove_Handler);
			if(skin_v != null)
			{
				style_v = new Vector.<Class>();
				style_v = skin_v;
				style_str_v = new <String>['background','colorWell','swatchSkin','swatchSelectedSkin',
					'textFieldSkin','disabledSkin','downSkin','overSkin','upSkin'];
				register_style(style_v);
			}
			CairngormEventDispatcher.getInstance().addEventListener(Skin_Event.skin_change_event,change_Handler);//所有不同ui更换
		}
		/**
		 * 设置样式
		 * @param v:样式数组
		 */		
		private function register_style(v:Vector.<Class>):void
		{
			var i:int = 0;
			for(i;i<style_length;i++)
			{
				this.setStyle(style_str_v[i],style_v[i]);
			}
		}
		private function remove_Handler(e:Event):void
		{
			this.removeEventListener(Event.REMOVED_FROM_STAGE,remove_Handler);
			CairngormEventDispatcher.getInstance().removeEventListener(Skin_Event.skin_change_event,change_Handler);//所有不同ui更换
		}
		/**
		 * 按钮更换样式 e.data可以是数字 代表第几套皮肤
		 */		
		private function change_Handler(e:Skin_Event):void
		{
			register_style(e.data);
		}
	}
}